package demo1.ioc;

//杯子
class Cup {
    private Goods goods;
    public Cup(Goods goods) {
        this.goods = goods;
    }
    public void init() {
        System.out.println("初始化Cup");
        goods.init();
    }
}

//物品
class Goods {
    private String one;
    public Goods(String one) {
        this.one = one;
    }
    public void init() {
        System.out.println("物品初始化为:" + one);
    }
}

public class ioc {
    public static void main(String[] args) {
        Goods goods = new Goods("water");
        Cup cup = new Cup(goods);
        cup.init();
    }
}
